package org.summerframework.component.security.enumeration;

/**
 * 登录来源
 *
 * @author 石超
 * @version v1.0.0
 */
public enum LoginFromEnum {

    LOGIN_FROM_ERROR(-1, "不认识的登录请求", false),
    LOGIN_FROM_WEBSITE(1, "官网", false),
    LOGIN_FROM_CLIENT_ANDROID(2, "android", true),
    LOGIN_FROM_CLIENT_IOS(3, "ios", true),
    LOGIN_FROM_CLIENT(4, "client", true);

    private int type;// 类型
    private String typeCode;// 类型符号
    private boolean isForEverSession;//是否是长连接

    LoginFromEnum(int type, String typeCode, boolean isForEverSession) {
        this.type = type;
        this.typeCode = typeCode;
        this.isForEverSession = isForEverSession;
    }

    public boolean isForEverSession() {
        return isForEverSession;
    }

    public Boolean getIsForEverSession() {
        return isForEverSession;
    }

    /**
     * 根据id返回类型enum
     *
     * @param type
     * @return
     */
    public static LoginFromEnum getByType(int type) {
        for (LoginFromEnum lt : values()) {
            if (lt.type == type) {
                return lt;
            }
        }
        return LOGIN_FROM_ERROR;
    }

    public boolean isType(int type) {
        return type == this.type;
    }

    /**
     * 根据code返回类型enum
     *
     * @return
     */
    public static LoginFromEnum getByCode(String typeCode) {
        for (LoginFromEnum lt : values()) {
            if (lt.typeCode.equalsIgnoreCase(typeCode)) {
                return lt;
            }
        }
        return LOGIN_FROM_ERROR;
    }

    public int getType() {
        return type;
    }

    public String getTypeCode() {
        return typeCode;
    }
}
